package com.example.springboot.service.admin.Impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot.mapper.MallRegionMapper;
import com.example.springboot.model.entity.MallRegion;
import com.example.springboot.model.form.PageUtil;
import com.example.springboot.model.form.Paging;
import com.example.springboot.model.form.Result;
import com.example.springboot.service.admin.MallRegionService;
import org.springframework.stereotype.Service;

/**
 * @author zf
 * @APP地址系统所有地址对应关系表
 * @since 2021-03-17
 */
@Service
public class MallRegionServiceImpl extends ServiceImpl<MallRegionMapper, MallRegion> implements MallRegionService {

    @Override
    public Result getPage(MallRegion req) {
        Paging paging = new Paging();

        IPage<MallRegion> ipage = page(paging.toPage(), new LambdaQueryWrapper<MallRegion>()
                .eq(MallRegion::getInvalid, 0)
                .orderByDesc(MallRegion::getCreateTime));

        Page<MallRegion> page = PageUtil.toPage(ipage);
        return Result.buildSuccess(PageUtil.convert(page, e -> {
//            VO vo = new VO();
            //主表复制元素
//            CopyUtil.copyObject(e, vo);
            return e;
        }));
    }

    @Override
    public Result deleteInfos(String ids) {
        boolean flag = update(new UpdateWrapper<MallRegion>().lambda()
                .set(MallRegion::getInvalid, 1)
                .inSql(MallRegion::getId, ids)
        );
        if (flag) {
            return Result.buildSuccess();
        }
        return Result.buildFail();
    }

}
